const ProductModel = require("../../models/productModel")

const productService = {
    add: async ({ userId, title, detail, introduction, cover, editTime }) => {
        return ProductModel.create({
            userId, title, detail, introduction, cover, editTime
        })
    },


    updateList: async ({ _id, title, introduction, detail, cover, editTime }) => {
        console.log(_id)
        console.log(7777)
        if (cover) {
            return ProductModel.updateOne({ _id }, {
                title, introduction, detail, cover, editTime
            })
        } else {
            return ProductModel.updateOne({ _id }, {
                title, introduction, detail, editTime
            })
        }
    },

    getList: async ({ _id }) => {
        console.log(global.userId)
        return _id ? ProductModel.find({ _id }) : ProductModel.find({ userId: global.userId })
    },

    delList: async ({ _id }) => {
        return ProductModel.deleteOne({ _id })
    },
}

module.exports = productService